#include <iostream> 
#include <fstream> 
#include <cmath> 
#include <algorithm> 
#include <cassert> 
#include <string> 
#include <cstdlib> 
#include <cstdio> 
#include <vector> 
#include <map> 
#include <set> 
#include <ctime>

#define itn int 
#define float long double 
#define LL long long
#define pb push_back
#define mp make_pair

using namespace std;

const int base = 1000000009;
const int key = 239;

void max_common_subsequence(const vector<string> & first, const vector<string> & second, int & index1, int & index2, int upper_bound_1, int upper_bound_2){
	while (index1 < upper_bound_1 && index2 < upper_bound_2 && first[index1] == second[index2]){
		index1++;
		index2++;
	}
}

void max_common_subsequence_back(const vector<string> & first, const vector<string> & second, int & index1, int & index2, int lower_bound_1, int lower_bound_2){
	while (index1 > lower_bound_1 && index2 > lower_bound_2 && first[index1 - 1] == second[index2 - 1]){
		index1--;
		index2--;
	}
}

string find_changes(const vector<string> & first, const vector<string> & second, int lower_bound_1, int upper_bound_1, int lower_bound_2, int upper_bound_2, int D){
	if (D == 0){	//D is a variable from the task, that's why it has only one letter
		string result = "";
		for (int i = lower_bound_1; i < upper_bound_1; i++) result += '\\';
		return result;
	}
	if (upper_bound_1 == lower_bound_1){
		string result = "";
		for (int i = lower_bound_2; i < upper_bound_2; i++) result += '-';
		return result;
	}
	if (upper_bound_2 == lower_bound_2){
		string result = "";
		for (int i = lower_bound_1; i < upper_bound_1; i++) result += '|';
		return result;
	}
	if (D == 1){	//the result shows a good way in our table
		int current_index1 = lower_bound_1, current_index2 = lower_bound_2;
		string result = "";
		while (current_index1 < upper_bound_1 && current_index2 < upper_bound_2 && first[current_index1] == second[current_index2]){
			result += '\\';
			current_index1++;
			current_index2++;
		}
		if (upper_bound_1 - lower_bound_1 < upper_bound_2 - lower_bound_2){
			result += '-';
			current_index2++;
		} else {
			result += '|';
			current_index1++;
		}
		while (current_index1 < upper_bound_1){
			result += '\\';
			current_index1++;
		}
		return result;
	}
	vector<pair<int, int> > first_distances((D + 3) / 2), helper_for_distances((D + 3) / 2), second_distances((D + 3) / 2);
	for (int d = 0; d <= (D + 1) / 2; d++){
		for (int i = 0; i <= d; i++){
			if (d == 0){
				int current_index1 = lower_bound_1, current_index2 = lower_bound_2;
                max_common_subsequence(first, second, current_index1, current_index2, upper_bound_1, upper_bound_2);
				first_distances[i] = mp(current_index1, current_index2);
			} else {
				first_distances[i] = mp(0, 0);
				pair<int, int> current_coordinates;
				if (i < d){
					current_coordinates = helper_for_distances[i];
					current_coordinates.first++;
					max_common_subsequence(first, second, current_coordinates.first, current_coordinates.second, upper_bound_1, upper_bound_2);
					if (first_distances[i].first < current_coordinates.first || first_distances[i].second < current_coordinates.second) first_distances[i] = current_coordinates;
				}
				if (i > 0){
					current_coordinates = helper_for_distances[i - 1];
					current_coordinates.second++;
					max_common_subsequence(first, second, current_coordinates.first, current_coordinates.second, upper_bound_1, upper_bound_2);
					if (first_distances[i].first < current_coordinates.first || first_distances[i].second < current_coordinates.second) first_distances[i] = current_coordinates;
				}
			}
		}
		swap(first_distances, helper_for_distances);
	}
	swap(first_distances, helper_for_distances);
	for (int d = 0; d <= D / 2; d++){
		for (int i = 0; i <= d; i++){
			if (d == 0){
				int current_index1 = upper_bound_1, current_index2 = upper_bound_2;
				max_common_subsequence_back(first, second, current_index1, current_index2, lower_bound_1, lower_bound_2);
				second_distances[i] = mp(current_index1, current_index2);
			} else {
				second_distances[i] = mp(upper_bound_1, upper_bound_2);
				pair<int, int> current_coordinates;
				if (i < d){
					current_coordinates = helper_for_distances[i];
					current_coordinates.second--;
					max_common_subsequence_back(first, second, current_coordinates.first, current_coordinates.second, lower_bound_1, lower_bound_2);
					if (second_distances[i].first > current_coordinates.first || second_distances[i].second > current_coordinates.second) second_distances[i] = current_coordinates;
				}
				if (i > 0){
					current_coordinates = helper_for_distances[i - 1];
					current_coordinates.first--;
					max_common_subsequence_back(first, second, current_coordinates.first, current_coordinates.second, lower_bound_1, lower_bound_2);
					if (second_distances[i].first > current_coordinates.first || second_distances[i].second > current_coordinates.second) second_distances[i] = current_coordinates;
				}
			}
		}
		swap(second_distances, helper_for_distances);
	}
	swap(second_distances, helper_for_distances);
	int mm = 0;
	for (int i = 0; i <= (D + 1) / 2; i++){
		if (2 * i + (upper_bound_1 - lower_bound_1) - (upper_bound_2 - lower_bound_2) - D % 2 >= 0 && 2 * i + (upper_bound_1 - lower_bound_1) - (upper_bound_2 - lower_bound_2) - D % 2 <= D + (D + 1) % 2 && first_distances[i].first >= second_distances[(2 * i + (upper_bound_1 - lower_bound_1) - (upper_bound_2 - lower_bound_2) - D % 2) / 2].first) mm = i;
	}
	return find_changes(first, second, lower_bound_1, first_distances[mm].first, lower_bound_2, first_distances[mm].second, (D + 1) / 2) + find_changes(first, second, first_distances[mm].first, upper_bound_1, first_distances[mm].second, upper_bound_2, D / 2);
}

void readall(ifstream & in, vector<string> & data){
	for (string line; getline(in, line); ){
		data.push_back(line);
	}
}

int get_answer(const vector<string> & data1, const vector<string> & data2, int size1, int size2){
	vector<pair<int, int> > distances(size2 + size1 + 1), helper_for_distances(size2 + size1 + 1);
	int answer = -1;
	for (int d = 0; d <= size2 + size1 && answer < 0; d++){
		for (int i = 0; i <= d && answer < 0; i++){
			if (d == 0){
				int current_index1 = 0, current_index2 = 0;
				max_common_subsequence(data1, data2, current_index1, current_index2, size1, size2);
				distances[i] = mp(current_index1, current_index2);
			} else {
				distances[i] = mp(0, 0);
				pair<int, int> current_coordinates;
				if (i < d){
					current_coordinates = helper_for_distances[i];
					current_coordinates.second++;
					max_common_subsequence(data1, data2, current_coordinates.first, current_coordinates.second, size1, size2);
					if (distances[i].first < current_coordinates.first || distances[i].second < current_coordinates.second) distances[i] = current_coordinates;
				}
				if (i > 0){
					current_coordinates = helper_for_distances[i - 1];
					current_coordinates.first++;
					max_common_subsequence(data1, data2, current_coordinates.first, current_coordinates.second, size1, size2);
					if (distances[i].first < current_coordinates.first || distances[i].second < current_coordinates.second) distances[i] = current_coordinates;
				}
			}
			if (distances[i].first == size1 && distances[i].second == size2){
				answer = d;
				break;
			}
		}
		swap(distances, helper_for_distances);
	}
	return answer;
}

int main(){ 
	
	clock_t start = clock();
	
	ifstream F1("file1.txt");
	ifstream F2("file2.txt");
	
	vector<string> data1, data2;
	readall(F1, data1);
	readall(F2, data2);
	int size1 = data1.size();
	int size2 = data2.size();
	F1.close();
	F2.close();

	int answer = get_answer(data1, data2, size1, size2);
	
	ofstream out("result.txt");
	
	out << answer << "\n";
	string transforms = find_changes(data1, data2, 0, size1, 0, size2, answer);
	int index1 = 0, index2 = 0;
	for (int _ = 0; _ < transforms.length(); _++){
		if (transforms[_] == '|') out << '-' << data1[index1++] << "\n"; else
		if (transforms[_] == '-') out << '+' << data2[index2++] << "\n"; else {
			out << data1[index1++] << "\n";
			index2++;
		}
	}
	
	clock_t finish = clock();
	out << "----------------------\nTotal work time is about " << (int)(finish - start) << " ticks or " << (int)(finish - start) / CLOCKS_PER_SEC << " seconds\n";
	
	out.close();
	
	return 0; 
} 
